package com.mxx.common.conv;


import com.mxx.common.utils.date.DateFormatterUtil;

import java.beans.PropertyEditorSupport;
import java.time.LocalDate;
import java.time.LocalDateTime;

public class StringLocalDateTimeEditor extends PropertyEditorSupport {


    @Override
    public void setValue(Object value) {
        if (value instanceof LocalDateTime) {
            LocalDateTime localDateTime = (LocalDateTime) value;
            super.setValue(localDateTime.format(DateFormatterUtil.dateTimeFormatter()));
        } else if (value instanceof LocalDate) {
            LocalDate localDate = (LocalDate) value;
            super.setValue(localDate.format(DateFormatterUtil.dateFormatter()));
        } else {
            super.setValue(value);
        }

    }

}
